package cn.edu.scau.cmi.qiuyaohua.client;

import java.util.ArrayList;

public class Org extends Group{
    private ArrayList<Group> member = new ArrayList<>();

    public Org(String name, Org p)
    {
        super(name,p);
    }

    @Override
    public String getInfo() {
        return "org:"+getName();
    }

    public int addMember(Group g)
    {
        if(member.add(g))
            return member.size();
        else return -1;
    }

    public boolean delMember(String name)
    {
        for(int i = 0;i<member.size()-1;i++)
        {
            if(name.compareTo(member.get(i).getName())==0)
            {
                member.remove(i);
                return true;
            }
        }
        return false;
    }

    public String printMember()
    {
        StringBuilder temp = new StringBuilder(name +" 成员:\n");
        for (Group g:member) {
            temp.append(g.getInfo());
            temp.append(' ');
        }
        return temp.toString();
    }

    public Group getMember(String name)
    {
        for (Group g:member) {
            if(name.compareTo(g.getName())==0)
            {
                return g;
            }
        }
        return null;
    }

}
